$("#gb").click(function () {
    let index=parent.layer.getFrameIndex(window.name);
    parent.layer.close(index);
})
$("#qx").click(function () {
    let index=parent.layer.getFrameIndex(window.name);
    parent.layer.close(index);
})
// console.log(localStorage.getItem("userId"));


$.ajax({
    type: 'get',
    url: '/backgroundmanagementpersonnellist/see',
    data:{userId:localStorage.getItem("userId")},
    success: function (res) {
        if(res.state == 200){
            $("span[name='userAccount']").text(res.data[0].userAccount);
            $("span[name='zhnc']").text(res.data[0].userNickname);
            $("input[name='userUrl']").val(res.data[0].userUrl);
            $("input[name='userAccount']").val(res.data[0].userAccount);
            $("input[name='userNickname']").val(res.data[0].userNickname);
            if(res.data[0].userSex == 1){
                $("input[name='userSex']").val("男");
            }else{
                $("input[name='userSex']").val("女");
            }

            $("input[name='userPhone']").val(res.data[0].userPhone);
            $("input[name='userIdCard']").val(res.data[0].userIdCard);
            $("input[name='userDateBirth']").val(res.data[0].userDateBirth);
            $("input[name='deptName']").val(res.data[0].department.deptName);
            $("input[name='userRegistrationTime']").val(res.data[0].userCreateDate);
            $("input[name='userRegisterIp']").val(res.data[0].userRegisterIp);
            $("input[name='userEmail']").val(res.data[0].userEmail);


            var obj = document.getElementById("tpxx");
            obj.src = 'http://43.143.176.39/'+res.data[0].userUrl;//能设置
        }

    }
})
layui.use(['form','laydate','upload'], function(){
    var form = layui.form;
    var laydate = layui.laydate;
    var upload = layui.upload;


    laydate.render({
        elem:'#userDateBirth',
        type:'datetime'
    })
    form.on('submit(tj)',function (d){
        console.log(d.field);
        if (d.field.userSex == '男'){
            d.field.userSex = 1
        }else {
            d.field.userSex = 0
        }
        $.ajax({
            type:"post",
            url:"/backgroundmanagementpersonnellist/syuseredit",
            data: {userId:localStorage.getItem("userId"),
                userNickname:d.field.userNickname,
                userSex:d.field.userSex,
                userPhone:d.field.userPhone,
                userIdCard:d.field.userIdCard,
                userDateBirth:d.field.userDateBirth,
                deptName:d.field.deptName,
                userEmail:d.field.userEmail,
                userUrl:d.field.userUrl
                },
            dataType:'json',

            success:function (res){
                if (res.state == 200){
                    layer.msg(res.msg,{time:500,icon:6})
                    let index=parent.layer.getFrameIndex(window.name);
                    parent.layer.close(index);
                    parent.backmalist();
                }
                else {
                    layer.msg(res.msg,{time:500,icon:5})
                }

            },
            error:function (e){
                layer.msg("请求异常")
            }
        })
        return false;
    })
    var uploadInst = upload.render({
        elem: '#ghtx'
        ,url: '/YltUpload'
        ,accept:'images'
        ,acceptMime:'image/jpg|image/png'
        ,size:50000
        ,before: function(obj){

            obj.preview(function(index, file, result){

                $("#tpxx").attr('src', result);
            });
        }
        ,done: function(res){
            //如果上传失败
            if(res.code > 0){
                return layer.msg('上传失败');
            }
            //上传成功
            else {
                console.log(res.data.fullPath);
                $("input[name='userUrl']").val(res.data.fullPath);
                return layer.msg('上传成功');
            }

        }
        ,error: function(){
            //演示失败状态，并实现重传
            layer.msg('失败');
        }
    })

})
